from typing import Optional
from fastapi import APIRouter, Request, Cookie, Depends
from fastapi.responses import HTMLResponse, RedirectResponse
from utils import validate_session
from templates import templates


router = APIRouter()

@router.get("/video-channels", response_class=HTMLResponse)
async def video_channels_page(
    request: Request,
    SessionId: Optional[str] = Cookie(None),
    UserName: Optional[str] = Cookie(None)
):
    if not SessionId or not UserName or not validate_session(SessionId, UserName):
        return RedirectResponse(url="/")
    return templates.TemplateResponse("video_channels.html", {
        "request": request,
        "UserName": UserName
    })

@router.get("/video-tasks", response_class=HTMLResponse)
async def video_tasks_page(
    request: Request,
    SessionId: Optional[str] = Cookie(None),
    UserName: Optional[str] = Cookie(None)
):
    if not SessionId or not UserName or not validate_session(SessionId, UserName):
        return RedirectResponse(url="/")
    return templates.TemplateResponse("video_tasks.html", {
        "request": request,
        "UserName": UserName
    })

@router.get("/realtime-preview", response_class=HTMLResponse)
async def realtime_preview_page(
    request: Request,
    SessionId: Optional[str] = Cookie(None),
    UserName: Optional[str] = Cookie(None)
):
    print("执行了这里")
    if not SessionId or not UserName or not validate_session(SessionId, UserName):
        return RedirectResponse(url="/")
    return templates.TemplateResponse("realtime_preview.html", {
        "request": request,
        "UserName": UserName
    })

@router.get("/playback", response_class=HTMLResponse)
async def playback_page(
    request: Request,
    SessionId: Optional[str] = Cookie(None),
    UserName: Optional[str] = Cookie(None)
):
    if not SessionId or not UserName or not validate_session(SessionId, UserName):
        return RedirectResponse(url="/")
    return templates.TemplateResponse("playback.html", {
        "request": request,
        "UserName": UserName
    })